import {getCount,
        getOrderCount,
        getVerification,
        loadOrderData,
        getOrderNumber,
        cancleOrder,
        getCollection,
        orderPay
} from '@/services'

const state={
    orderAmount:{},
    collectionCount:0,
    records:[],
    shopDetail:{},
    sts:0,
    collectionList:[],
    current:1,
    size:10,
    payres:{}
};

const mutations = {
    update(state,payload){
        for(let key in payload){
            state[key]=payload[key]
        }
    }
};

const actions = {
    async getCount({ commit }) {
        let result = await getCount();
        commit('update',{
            collectionCount:result
        })
    },
    async getOrderCount({ commit }) {
        let result = await getOrderCount();
        commit('update',{
            orderAmount:result
        })
    },
    async loadOrderData({ commit },sts) {
        let result = await loadOrderData(sts);
        commit('update',{
            records:result.records,
            sts:sts
        })
    },
    async getVerification({ commit },mobile) {
        let result = await getVerification(mobile);
        console.log(result);
        // commit('update',{
        //     orderAmount:result
        // })
    },
    async getOrderNumber({ commit },orderNumber) {
        let result = await getOrderNumber(orderNumber);
        commit('update',{
            shopDetail:result
        })
    },
    async cancleOrder({ commit },ordernum) {
        let result = await cancleOrder(ordernum);
        console.log(result,'cancel......');
        // commit('update',{
        //     shopDetail:result
        // })
    },
    async getCollection({ commit },payload) {
        let {current=1,size=10} =payload
        let result = await getCollection({current,size});
        console.log(result);
        commit('update',{
            collectionList:result.records
        })
    },
    async orderPay({ commit },orderNumbers) {
        let result = await orderPay({payType:1,orderNumbers});
        console.log(result);
        commit('update',{
            payres:result
        })
    },
};

export default {
    namespaced: true,
    state,
    mutations,
    actions,
};
  